package com.fs.groupSeven.controller;

import com.fs.groupSeven.pojo.*;
import com.fs.groupSeven.service.ClassroomService;
import com.fs.groupSeven.service.TeachingInformationService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Date;
import java.util.*;

@Controller
@RequestMapping("/teachingInformation")
public class TeachingInformationController {

    @Autowired
    private TeachingInformationService teachingInformationService;

    @GetMapping("/classTeachingManage")
    public String getClassroomView() {
        //返回页面
        return "teachingInformationManageSTWH/classTeachingManage";
    }

    @GetMapping("/teachingManage")
    public String getClassroomView1() {
        //返回页面
        return "teachingInformationManageSTWH/teachingManage";
    }

    @RequestMapping("/getOneByClassName")
    @ResponseBody
    public Map<String, Object> getOneByClassName(){
        List<String> classList = teachingInformationService.getClassName();
        List<List> lists = new ArrayList<>();

        for (String classname : classList) {
            List<TeachingInformation> teachingInformationList = teachingInformationService.getAllByClassName(classname);
            lists.add(teachingInformationList);
        }

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("message", "获取用户数据成功");
        result.put("lists", lists);
        return result;
    }

    @RequestMapping("/getOneByClassName2")
    @ResponseBody
    public Map<String, Object> getOneByClassName2(){
        List<String> classList = teachingInformationService.getClassName();
        List<List> lists = new ArrayList<>();

        for (String classname : classList) {
            List<TeachingInformation> teachingInformationList = teachingInformationService.getAllByClassName2(classname);
            lists.add(teachingInformationList);
        }

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("message", "获取用户数据成功");
        result.put("lists", lists);
        return result;
    }

    @RequestMapping("/getOneByCode")
    @ResponseBody
    public Map<String, Object> getOneByCode(String code){
        Map<String, Object> result = new HashMap<>();

        TeachingInformation teachingInformation = teachingInformationService.getAllByCode(code);
        List<MyTeacherTest> teacher = teachingInformationService.getAllBySubjectId(teachingInformation.getSubject_id());
        List<MyClassRoomTest> classroom = teachingInformationService.getClassRoom();

        result.put("code", 0);
        result.put("message", "获取用户数据成功");
        result.put("teachingInformation", teachingInformation);
        result.put("teacher",teacher);
        result.put("classroom",classroom);
        return result;
    }

    @RequestMapping("/myChange")
    @ResponseBody
    public Map<String, Object> myChange(Integer class_id,String identifier,String oldsubjectname,String subjectname, Integer teacher_id, Integer classroom_id, Integer oldclassroom_id,String duration, String time_on,String time_off){
        if (subjectname != null || duration != null){
            teachingInformationService.modifySubject(oldsubjectname,subjectname,duration);
        }
        if (time_on != null || time_off != null){
            teachingInformationService.modifySchedule(time_on,time_off,identifier);
        }
        if (classroom_id != null || classroom_id != null){
            teachingInformationService.modifyClassroom(class_id,classroom_id);
            teachingInformationService.modifyOldClassroom(oldclassroom_id);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
//        result.put("lists", lists);
        return result;
    }

    @RequestMapping("/myDelete")
    @ResponseBody
    public Map<String, Object> myDelete(Integer class_id,Integer subject_id){
        teachingInformationService.deleteClassSubject(class_id,subject_id);
        teachingInformationService.deleteSchedule(class_id,subject_id);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
//        result.put("lists", lists);
        return result;
    }

    @RequestMapping("/getSomething")
    @ResponseBody
    public Map<String, Object> getSomething(Integer college_id,Integer class_id){
        List<MySubjectTest> subject = teachingInformationService.getSubject(college_id);
        String classroom = teachingInformationService.getClassRoomByClassId(class_id);

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("message", "获取用户数据成功");
        result.put("subject", subject);
        result.put("classroom", classroom);
        return result;
    }

    @RequestMapping("/getSomething2")
    @ResponseBody
    public Map<String, Object> getSomething2(Integer subject_id){
        String subject = teachingInformationService.getSubjectBySid(subject_id);
        List<MyTeacherTest> teacher = teachingInformationService.getAllBySubjectId(subject_id);

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("message", "获取用户数据成功");
        result.put("subject", subject);
        result.put("teacher", teacher);
        return result;
    }

    @RequestMapping("/myAdd")
    @ResponseBody
    public Map<String, Object> myAdd(Integer class_id,Integer subject_id,String time_on,String time_off,String identifier){
        teachingInformationService.insertClassSubject(class_id,subject_id);

        teachingInformationService.insertSchedule(class_id,subject_id,time_on,time_off,identifier);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
//        result.put("lists", lists);
        return result;
    }
}
